

farbe1 <- "#f1a340"
farbe2 <- "#998ec3"

# farbe1a <- alpha("orange",.4)
# farbe2b <- alpha("purple",.4)

farbe1a <- "#f1a34066"
farbe2b <- "#998ec366"

data.plot <- data.frame(n.weib$y,n.weib$yhat,sp.weib.v$yhat)
names(data.plot) <- c("y","n.yhat","sp.yhat")
data.plot$abs.n <-   abs(data.plot$y - data.plot$n.yhat)
data.plot$abs.sp  <- abs(data.plot$y - data.plot$sp.yhat)
data.plot <- data.plot[order(data.plot$y),]

table(ifelse(data.plot$abs.n<data.plot$abs.sp,"Ncloser","SPcloser") )

r1rmse <- sqrt(mean((n.weib$y - n.weib$yhat)^2))
r2rmse <- sqrt(mean((n.weib$y - sp.weib.v$yhat)^2))
rsme1 <- paste("RSME",round(r1rmse,2),sep="=")
rsme2 <- paste("RSME",round(r2rmse,2),sep="=")

setwd(pathDATA)

# Figure 3: twobytwoa.pdf, twobytwob.pdf, twobytwod.pdf
# Figure C1: twobytwoc.pdf

pdf(file="twobytwoa.pdf",width=5,height=5)
par(bg="white")
#par(mfrow=c(2,2))
plot(density(n.weib$y), ylim=c(0, max(density(n.weib$y)$y)), xlim= c(0,10000),ann=FALSE,axes=FALSE,lwd=2)
lines(density(n.weib$yhat), col=farbe1,lwd=2)
lines(density(sp.weib.v$yhat), col=farbe2,lwd=2)
polygon(density(n.weib$yhat),col=farbe1a,border=FALSE)
polygon(density(sp.weib.v$yhat),col=farbe2b,border=FALSE)

#lines(c(median(n.weib$y),median(n.weib$y)),c(0,100))
#lines(c(median(n.weib$yhat),median(n.weib$yhat)),c(0,100),col=farbe1)
#lines(c(median(sp.weib$yhat),median(sp.weib$yhat)),c(0,100),col=farbe2)
axis(2,las= HORIZONTAL<-1)
axis(1)
title(ylab="Density",xlab="Rebel organization duration")
dev.off()


pdf(file="twobytwob.pdf",width=5,height=5)
par(bg="white")
closer <- table(ifelse(data.plot$abs.n>data.plot$abs.sp,2,1))
barplot(closer,col=c(farbe1,farbe2),names.arg=c(paste("Naive",rsme1,sep="/"),paste("Spatial",rsme2,sep="/")),axes=F,ann=F)
axis(2,las= HORIZONTAL<-1)
title(ylab="Times closer to true duration",xlab="")
dev.off()


pdf(file="twobytwoc.pdf",width=5,height=5)
par(bg="white")
plot(c(-12000,12000),c(0,11000),type="n",ann=FALSE,axes=FALSE)
segments(rep(0,dim(data.plot)[1]),data.plot$y,-data.plot$abs.n,data.plot$y,col=ifelse(data.plot$abs.n<data.plot$abs.sp,farbe1,farbe1))
segments(rep(0,dim(data.plot)[1]),data.plot$y,data.plot$abs.sp,data.plot$y,col=ifelse(data.plot$abs.n>data.plot$abs.sp,farbe2,farbe2))
axis(2,las= HORIZONTAL<-1)
axis(1,at=c(-10000,0,10000),lab=c("10000","0","10000"))
title(ylab="Observed Duration of Conflict",xlab="Absolute deviation of estimated duration")
dev.off()


pdf(file="twobytwod.pdf",width=5,height=5)
par(bg="white")
plot(c(-5000,5000),c(0,11000),type="n",ann=FALSE,axes=FALSE)
segments(rep(0,dim(data.plot)[1]),data.plot$y,data.plot$abs.n-data.plot$abs.sp,data.plot$y,col=ifelse(data.plot$abs.n<data.plot$abs.sp,farbe1,farbe2))
axis(2,las= HORIZONTAL<-1)
axis(1,at=c(-4000,-2000,0,2000,4000),lab=c("4000","2000","0","2000","4000"))
title(ylab="Observed Duration of Conflict",xlab="Advantage in absolute deviation")

dev.off()


# Figure 4: Separatist twobytwoaS.pdf, twobytwobS.pdf, twobytwodS.pdf
#			Non-Separatist twobytwoaNS.pdf, twobytwobNS.pdf, twobytwodNS.pdf
#########################
#Secession 
#########################

farbe1 <- "#f1a340"
farbe2 <- "#998ec3"

# farbe1a <- alpha("orange",.4)
# farbe2b <- alpha("purple",.4)

farbe1a <- "#f1a34066"
farbe2b <- "#998ec366"

data.plot <- data.frame(n.weib.s$y,n.weib.s$yhat,sp.weib.s$yhat)
names(data.plot) <- c("y","n.yhat","sp.yhat")
data.plot$abs.n <-   abs(data.plot$y - data.plot$n.yhat)
data.plot$abs.sp  <- abs(data.plot$y - data.plot$sp.yhat)
data.plot <- data.plot[order(data.plot$y),]

table(ifelse(data.plot$abs.n<data.plot$abs.sp,"Ncloser","SPcloser") )


r1rmse <- sqrt(mean((n.weib.s$y - n.weib.s$yhat)^2))
r2rmse <- sqrt(mean((n.weib.s$y - sp.weib.s$yhat)^2))
rsme1 <- paste("RSME",round(r1rmse,2),sep="=")
rsme2 <- paste("RSME",round(r2rmse,2),sep="=")

setwd(pathDATA)

pdf(file="twobytwoaS.pdf",width=5,height=5)
par(bg="white")
#par(mfrow=c(2,2))
plot(density(n.weib.s$y), ylim=c(0, max(density(n.weib.s$y)$y)), xlim= c(0,10000),ann=FALSE,axes=FALSE,lwd=2)
lines(density(n.weib.s$yhat), col=farbe1,lwd=2)
lines(density(sp.weib.s$yhat), col=farbe2,lwd=2)
polygon(density(n.weib.s$yhat),col=farbe1a,border=FALSE)
polygon(density(sp.weib.s$yhat),col=farbe2b,border=FALSE)

#lines(c(median(n.weib$y),median(n.weib$y)),c(0,100))
#lines(c(median(n.weib$yhat),median(n.weib$yhat)),c(0,100),col=farbe1)
#lines(c(median(sp.weib$yhat),median(sp.weib$yhat)),c(0,100),col=farbe2)
axis(2,las= HORIZONTAL<-1)
axis(1)
title(ylab="Density",xlab="Rebel organization duration")
dev.off()


pdf(file="twobytwobS.pdf",width=5,height=5)
par(bg="white")
closer <- table(ifelse(data.plot$abs.n>data.plot$abs.sp,2,1))
barplot(closer,col=c(farbe1,farbe2),names.arg=c(paste("Naive",rsme1,sep="/"),paste("Spatial",rsme2,sep="/")),axes=F,ann=F)
axis(2,las= HORIZONTAL<-1)
title(ylab="Times closer to true duration",xlab="")
dev.off()


pdf(file="twobytwocS.pdf",width=5,height=5)
par(bg="white")
plot(c(-12000,12000),c(0,11000),type="n",ann=FALSE,axes=FALSE)
segments(rep(0,dim(data.plot)[1]),data.plot$y,-data.plot$abs.n,data.plot$y,col=ifelse(data.plot$abs.n<data.plot$abs.sp,farbe1,farbe1))
segments(rep(0,dim(data.plot)[1]),data.plot$y,data.plot$abs.sp,data.plot$y,col=ifelse(data.plot$abs.n>data.plot$abs.sp,farbe2,farbe2))
axis(2,las= HORIZONTAL<-1)
axis(1,at=c(-10000,0,10000),lab=c("10000","0","10000"))
title(ylab="Observed Duration of Conflict",xlab="Absolute deviation of estimated duration")
dev.off()


pdf(file="twobytwodS.pdf",width=5,height=5)
par(bg="white")
plot(c(-5000,5000),c(0,11000),type="n",ann=FALSE,axes=FALSE)
segments(rep(0,dim(data.plot)[1]),data.plot$y,data.plot$abs.n-data.plot$abs.sp,data.plot$y,col=ifelse(data.plot$abs.n<data.plot$abs.sp,farbe1,farbe2))
axis(2,las= HORIZONTAL<-1)
axis(1,at=c(-4000,-2000,0,2000,4000),lab=c("4000","2000","0","2000","4000"))
title(ylab="Observed Duration of Conflict",xlab="Advantage in absolute deviation")

dev.off()


#########################
#No Secession 
#########################


farbe1 <- "#f1a340"
farbe2 <- "#998ec3"

# farbe1a <- alpha("orange",.4)
# farbe2b <- alpha("purple",.4)

farbe1a <- "#f1a34066"
farbe2b <- "#998ec366"

data.plot <- data.frame(n.weib.ns$y,n.weib.ns$yhat,sp.weib.ns$yhat)
names(data.plot) <- c("y","n.yhat","sp.yhat")
data.plot$abs.n <-   abs(data.plot$y - data.plot$n.yhat)
data.plot$abs.sp  <- abs(data.plot$y - data.plot$sp.yhat)
data.plot <- data.plot[order(data.plot$y),]

table(ifelse(data.plot$abs.n<data.plot$abs.sp,"Ncloser","SPcloser") )


r1rmse <- sqrt(mean((n.weib.ns$y - n.weib.ns$yhat)^2))
r2rmse <- sqrt(mean((n.weib.ns$y - sp.weib.ns$yhat)^2))
rsme1 <- paste("RSME",round(r1rmse,2),sep="=")
rsme2 <- paste("RSME",round(r2rmse,2),sep="=")

setwd(pathDATA)


pdf(file="twobytwoaNS.pdf",width=5,height=5)
par(bg="white")
#par(mfrow=c(2,2))
plot(density(n.weib.ns$y), ylim=c(0, max(density(n.weib.ns$y)$y)), xlim= c(0,10000),ann=FALSE,axes=FALSE,lwd=2)
lines(density(n.weib.ns$yhat), col=farbe1,lwd=2)
lines(density(sp.weib.ns$yhat), col=farbe2,lwd=2)
polygon(density(n.weib.ns$yhat),col=farbe1a,border=FALSE)
polygon(density(sp.weib.ns$yhat),col=farbe2b,border=FALSE)

#lines(c(median(n.weib$y),median(n.weib$y)),c(0,100))
#lines(c(median(n.weib$yhat),median(n.weib$yhat)),c(0,100),col=farbe1)
#lines(c(median(sp.weib$yhat),median(sp.weib$yhat)),c(0,100),col=farbe2)
axis(2,las= HORIZONTAL<-1)
axis(1)
title(ylab="Density",xlab="Rebel organization duration")
dev.off()


pdf(file="twobytwobNS.pdf",width=5,height=5)
par(bg="white")
closer <- table(ifelse(data.plot$abs.n>data.plot$abs.sp,2,1))
barplot(closer,col=c(farbe1,farbe2),names.arg=c(paste("Naive",rsme1,sep="/"),paste("Spatial",rsme2,sep="/")),axes=F,ann=F)
axis(2,las= HORIZONTAL<-1)
title(ylab="Times closer to true duration",xlab="")
dev.off()


pdf(file="twobytwocNS.pdf",width=5,height=5)
par(bg="white")
plot(c(-12000,12000),c(0,11000),type="n",ann=FALSE,axes=FALSE)
segments(rep(0,dim(data.plot)[1]),data.plot$y,-data.plot$abs.n,data.plot$y,col=ifelse(data.plot$abs.n<data.plot$abs.sp,farbe1,farbe1))
segments(rep(0,dim(data.plot)[1]),data.plot$y,data.plot$abs.sp,data.plot$y,col=ifelse(data.plot$abs.n>data.plot$abs.sp,farbe2,farbe2))
axis(2,las= HORIZONTAL<-1)
axis(1,at=c(-10000,0,10000),lab=c("10000","0","10000"))
title(ylab="Observed Duration of Conflict",xlab="Absolute deviation of estimated duration")
dev.off()


pdf(file="twobytwodNS.pdf",width=5,height=5)
par(bg="white")
plot(c(-5000,5000),c(0,11000),type="n",ann=FALSE,axes=FALSE)
segments(rep(0,dim(data.plot)[1]),data.plot$y,data.plot$abs.n-data.plot$abs.sp,data.plot$y,col=ifelse(data.plot$abs.n<data.plot$abs.sp,farbe1,farbe2))
axis(2,las= HORIZONTAL<-1)
axis(1,at=c(-4000,-2000,0,2000,4000),lab=c("4000","2000","0","2000","4000"))
title(ylab="Observed Duration of Conflict",xlab="Advantage in absolute deviation")

dev.off()

###################################################
###################################################





